// run: $exec < input
#include <cstring>
#include <cstdio>
#include <cstdlib>
const	int nn = 101;
bool map[nn][nn];
int  f[nn][nn<<1], g[nn][nn<<1];
int  co[nn], part[nn], dl[nn], dr[nn], ans1[nn], ans2[nn], pp[nn];
int  n, tot;

void init()
{
	memset(map, 0, sizeof(map));
	memset(ans1, 0, sizeof(ans1));
	memset(ans2, 0, sizeof(ans2));
	scanf("%d", &n);
	int i, j, x;
	for (i=1; i<=n; i++)
		while (scanf("%d", &x) && x) map[i][x] = true;
	for (i=1; i<=n; i++) {
		for (j=i+1; j<=n; j++) {
			if ((!map[i][j])||(!map[j][i])) map[i][j] = map[j][i] = true;
			else						    map[i][j] = map[j][i] = false;
		}
		map[i][i] = false;
	}
}

bool judge()                       //co 1 means black    2 means white       
{
	memset(part, 0, sizeof(part));
	memset(co, 0, sizeof(co));
	tot = 0;
	for (int i=1; i<=n; i++)
		if (!co[i]) {
			int t = 1, len = 1, cb = 1, cw = 0;
			tot++;  part[i] = tot;
			pp[t] = i;  co[i] = 1;
			while (t <= len) {
				int x = pp[t];
				for (int j=1; j<=n; j++)
				if (map[x][j]) {
					if (!co[j]) {
						co[j] = 3-co[x];
						pp[++len] = j;
						part[j] = tot;
						if (co[j] == 1) cb++;
						else 			cw++;
					}
					else if (co[j] == co[x]) return false;
				}
				t++;
			}
			dl[tot] = cb;  dr[tot] = cw;
		}
	return true;
}

void dp()
{
	memset(f, 0, sizeof(f));
	memset(g, 0, sizeof(g));
	f[1][dl[1]-dr[1]+n] = 1;
	f[1][dr[1]-dl[1]+n] = 2;
	int i, j;
	for (i=2; i<=tot; i++) {
		for (j=0; j<=2*n; j++) {
			int tmp = j-dl[i]+dr[i];   //l-r 2     r-l 1
			if ((tmp>=0)&&(tmp<=2*n)&&f[i-1][tmp]) {
				f[i][j] = 1;  g[i][j] = tmp;
			}
			tmp = j+dl[i]-dr[i];
			if ((tmp>=0)&&(tmp<=2*n)&&f[i-1][tmp]) {
				f[i][j] = 2;  g[i][j] = tmp;
			}
		}
	}
	int pos;
	for (j=0; j<=n; j++)
		if (f[tot][n+j]) {
			pos = n+j;  break;
		}
		else if (f[tot][n-j]) {
			pos = n-j;  break;
		}
	int t = tot;
	while (t) {
		if (f[t][pos] == 1) {
			for (i=1; i<=n; i++)
				if (part[i] == t) {
					if (co[i] == 1) ans1[++ans1[0]] = i;
					else		    ans2[++ans2[0]] = i;
				}
		}
		else {
			for (i=1; i<=n; i++)
				if (part[i] == t) {
					if (co[i] == 2) ans1[++ans1[0]] = i;
					else		    ans2[++ans2[0]] = i;
				}
		}
		pos = g[t][pos];
		t--;
	}
	printf("%d", ans1[0]);
	for (i=1; i<=ans1[0]; i++) printf(" %d", ans1[i]);
	printf("\n%d", ans2[0]);
	for (i=1; i<=ans2[0]; i++) printf(" %d", ans2[i]);
	std::printf("\n");
}

void work()
{
	if (!judge()) printf("No solution\n");
	else dp();
}

int main()
{
//	freopen("ttt.in","r",stdin);	freopen("ttt.out","w",stdout);
	int T; std::scanf("%d", &T);
	for (int ti = 1; ti <= T; ti++) {
		if (ti > 1) std::printf("\n");
		init();
		work();
	}
}

